$().ready(function(){
    var nav = getSearch('nav');
    var navList = {};
    for(let i in mainList){
        if(nav == mainList[i].id){
            navList = mainList[i];
        }
    }
    var item = getSearch('item');
    // console.log(item);
    var navItem = '';
    for(let j in navList.list){
        if(item == navList.list[j].id){
            navItem = navList.list[j];
        }
    }

    var breadcream = '<a href="index.html">首页</a>';
    breadcream += '<a href="'+navList.link+'?nav='+navList.id+'">'+navList.name+'</a>';
    // breadcream += '<a href="">'+navItem.name+'</a>';
    $('#breadcream').html(breadcream);
    var apiUrl = '/Api/New/get_jtxw';
    var page = 1;
    var newsList;
    function getNewsList(apiUrl,page){
        getAjax(apiUrl,res=>{
            console.log(res);
            var html = '';
            if(res.list.length == 0){
                html = '<div class="m-no-news">-暂无新闻-</div>'
            }else{
                if(page == 1){
                    newsList = [];
                    newsList = res.list;
                }else{
                    newsList = newsList.concat(res.list);
                    console.log(newsList);
                }
                html = '<div class="head-news">';
                html += '<a href="arctical.html?nav='+nav+'&item='+item+'&id='+newsList[0].id+'">';
                html += '<div class="head-news-img">';
                html += '<img src="'+newsList[0].title_img+'" alt="">';
                html += '</div><div class="head-news-title head-style">';
                html += '<div class="news-send-date">'+newsList[0].date+'</div>';
                html += '<div class="title-text">'+newsList[0].title+'</div></div>';
                html += '<div class="m-news-sub-content">'+newsList[0].sub_content+'</div>';
                html += ' <div class="today-headline">头条详情</div></a></div>';
                for(var i=1;i<newsList.length;i++){
                    html += '<div class="head-news">';
                    html += '<a href="arctical.html?nav='+nav+'&item='+item+'&id='+newsList[i].id+'">';
                    html += '<div class="head-news-title">';
                    html += '<div class="news-send-date">'+newsList[i].date+'</div>';
                    html += '<div class="title-text">'+newsList[i].title+'</div></div>';
                    html += '<div class="m-news-sub-content">'+newsList[i].sub_content+'</div>';
                    html += '</a></div>';
                }
                if(res.ok == 0){
                    html += '<div class="no-more">-无更多新闻-</div>'

                }else if(res.ok == 1){
                    html += '<div id="getMore">查看更多</div>'
                }
            }

            $('#main-news-box').html(html)
        },{p:page,num:5})
    }
    getNewsList(apiUrl,page)
    $('#main-news-box').on('click','#getMore',function(){
        console.log(1);
        page++;
        getNewsList(apiUrl,page)
    })
})
